Conditions | 1 |
Paths | 1 |
Total Lines | 420 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
9 | describe('Root', function(){ |
||
10 | |||
11 | var fullJSON = { |
||
12 | id: 'gedcomx', |
||
13 | lang: 'en', |
||
14 | description: '#sd1', |
||
15 | attribution: { |
||
16 | changeMessage: 'It changed', |
||
17 | contributor: { resource: 'https://myapp.com/contributor'}, |
||
18 | created: 1111338494969, |
||
19 | creator: { resource: 'https://myapp.com/creator'}, |
||
20 | modified: 1111338494969 |
||
21 | }, |
||
22 | persons: [ |
||
23 | { |
||
24 | private: false, |
||
25 | gender: { |
||
26 | type: 'http://gedcomx.org/Female' |
||
27 | }, |
||
28 | names: [ |
||
29 | { |
||
30 | type: 'http://gedcomx.org/BirthName', |
||
31 | nameForms: [ |
||
32 | { |
||
33 | fullText: 'Joanna Hopkins' |
||
34 | } |
||
35 | ] |
||
36 | } |
||
37 | ], |
||
38 | facts: [ |
||
39 | { |
||
40 | type: 'http://gedcomx.org/Birth', |
||
41 | date: { |
||
42 | formal: '+2001-04-09' |
||
43 | }, |
||
44 | place: { |
||
45 | original: 'Farm house' |
||
46 | } |
||
47 | } |
||
48 | ] |
||
49 | } |
||
50 | ], |
||
51 | relationships: [ |
||
52 | { |
||
53 | type: 'http://gedcomx.org/Couple', |
||
54 | person1: { |
||
55 | resource: 'http://identifier/for/person/1' |
||
56 | }, |
||
57 | person2: { |
||
58 | resource: 'http://identifier/for/person/2' |
||
59 | }, |
||
60 | facts: [ |
||
61 | { |
||
62 | type: 'http://gedcomx.org/Marriage' |
||
63 | } |
||
64 | ] |
||
65 | } |
||
66 | ], |
||
67 | sourceDescriptions: [ |
||
68 | { |
||
69 | id: 'sd1', |
||
70 | resourceType: 'http://some/type', |
||
71 | citations: [ |
||
72 | { |
||
73 | lang: 'en', |
||
74 | value: 'Long source citation' |
||
75 | } |
||
76 | ], |
||
77 | mediaType: 'book', |
||
78 | about: 'http://a/resource', |
||
79 | mediator: { |
||
80 | resource: 'http://mediator' |
||
81 | }, |
||
82 | sources: [ |
||
83 | { |
||
84 | description: 'http://source/reference' |
||
85 | } |
||
86 | ], |
||
87 | analysis: { |
||
88 | resource: 'http://analysis' |
||
89 | }, |
||
90 | componentOf: { |
||
91 | description: 'http://container' |
||
92 | }, |
||
93 | titles: [ |
||
94 | { |
||
95 | lang: 'en', |
||
96 | value: 'Title' |
||
97 | }, |
||
98 | { |
||
99 | lang: 'es', |
||
100 | value: 'Titulo' |
||
101 | } |
||
102 | ], |
||
103 | notes: [ |
||
104 | { |
||
105 | subject: 'Note', |
||
106 | text: 'Some note text' |
||
107 | } |
||
108 | ], |
||
109 | attribution: { |
||
110 | created: 1234578129 |
||
111 | }, |
||
112 | rights: [ |
||
113 | { |
||
114 | resource: 'https://some/right' |
||
115 | } |
||
116 | ], |
||
117 | coverage: { |
||
118 | temporal: { |
||
119 | formal: '+2015' |
||
120 | }, |
||
121 | spatial: { |
||
122 | original: 'A place' |
||
123 | } |
||
124 | }, |
||
125 | descriptions: [ |
||
126 | { |
||
127 | value: 'A description' |
||
128 | } |
||
129 | ], |
||
130 | identifiers: { |
||
131 | $: 'identifier' |
||
132 | }, |
||
133 | created: 1000000, |
||
134 | modified: 11111111, |
||
135 | repository: { |
||
136 | resource: 'http://repository' |
||
137 | } |
||
138 | } |
||
139 | ], |
||
140 | agents: [ |
||
141 | { |
||
142 | id: 'agent', |
||
143 | identifiers: { |
||
144 | $: 'ident' |
||
145 | }, |
||
146 | names: [ |
||
147 | { |
||
148 | lang: 'en', |
||
149 | value: 'Name' |
||
150 | } |
||
151 | ], |
||
152 | homepage: { |
||
153 | resource: 'http://homepage' |
||
154 | }, |
||
155 | openid: { |
||
156 | resource: 'http://openid' |
||
157 | }, |
||
158 | accounts: [ |
||
159 | { |
||
160 | accountName: 'jimbo' |
||
161 | } |
||
162 | ], |
||
163 | emails: [ |
||
164 | { |
||
165 | resource: 'http://email' |
||
166 | } |
||
167 | ], |
||
168 | phones: [ |
||
169 | { |
||
170 | resource: 'http://phone' |
||
171 | } |
||
172 | ], |
||
173 | addresses: [ |
||
174 | { |
||
175 | value: 'big long address', |
||
176 | postalCode: '123456' |
||
177 | } |
||
178 | ], |
||
179 | person: { |
||
180 | resource: 'http://person' |
||
181 | } |
||
182 | } |
||
183 | ], |
||
184 | events: [ |
||
185 | { |
||
186 | type: 'http://gedcomx.org/Marriage', |
||
187 | date: { |
||
188 | formal: '+2002-06-06' |
||
189 | }, |
||
190 | place: { |
||
191 | original: 'Her town, MN' |
||
192 | }, |
||
193 | roles: [ |
||
194 | { |
||
195 | person: { |
||
196 | resource: 'http://groom' |
||
197 | }, |
||
198 | type: 'http://gedcomx.org/Participant' |
||
199 | } |
||
200 | ] |
||
201 | } |
||
202 | ], |
||
203 | documents: [ |
||
204 | { |
||
205 | type: 'http://gedcomx.org/Abstract', |
||
206 | extracted: false, |
||
207 | textType: 'plain', |
||
208 | text: 'Lots of text', |
||
209 | attribution: { |
||
210 | created: 123456789 |
||
211 | } |
||
212 | } |
||
213 | ], |
||
214 | places: [ |
||
215 | { |
||
216 | names : [ |
||
217 | { |
||
218 | lang : 'en', |
||
219 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
220 | } |
||
221 | ], |
||
222 | type : 'http://identifier/for/the/place/type', |
||
223 | place : { resource : 'http://place' }, |
||
224 | jurisdiction : { resource : 'http://jurisdiction' }, |
||
225 | latitude : 27.9883575, |
||
226 | longitude : 86.9252014, |
||
227 | temporalDescription : { |
||
228 | formal: '+1899-01-04' |
||
229 | }, |
||
230 | spatialDescription : { |
||
231 | resource : 'http://uri/for/KML/document' |
||
232 | } |
||
233 | } |
||
234 | ], |
||
235 | recordDescriptors: [ |
||
236 | { |
||
237 | id: 'rd', |
||
238 | lang: 'en-US', |
||
239 | fields: [{ |
||
240 | originalLabel: 'Name', |
||
241 | descriptions: [ |
||
242 | { lang: 'en-US', value: 'Full Name' } |
||
243 | ], |
||
244 | values: [{ |
||
245 | optional: true, |
||
246 | type: 'http://gedcomx.org/Original', |
||
247 | labelId: 'name', |
||
248 | displayLabels: [ |
||
249 | { lang: 'en-US', value: 'Name' } |
||
250 | ] |
||
251 | }] |
||
252 | }] |
||
253 | } |
||
254 | ], |
||
255 | collections: [ |
||
256 | { |
||
257 | id: 'collection', |
||
258 | lang: 'en-US', |
||
259 | content: [{ |
||
260 | resourceType: 'http://gedcomx.org/Record', |
||
261 | count: 183429102, |
||
262 | completeness: .8237 |
||
263 | }], |
||
264 | title: 'Collection Title', |
||
265 | size: 183429102, |
||
266 | attribution: { |
||
267 | contributor: { resource: 'https://myapp.com/contributor'}, |
||
268 | created: 1111338494969, |
||
269 | creator: { resource: 'https://myapp.com/creator'}, |
||
270 | modified: 1111338494969 |
||
271 | } |
||
272 | } |
||
273 | ] |
||
274 | }; |
||
275 | |||
276 | it('Create with JSON', function(){ |
||
277 | var gedx = GedcomX(fullJSON); |
||
278 | tests(gedx); |
||
279 | }); |
||
280 | |||
281 | it('Build', function(){ |
||
282 | var gedx = GedcomX() |
||
283 | .setId('gedcomx') |
||
284 | .setLang('en') |
||
285 | .setDescription('#sd1') |
||
286 | .setAttribution(GedcomX.Attribution() |
||
287 | .setChangeMessage('It changed') |
||
288 | .setContributor({ resource: 'https://myapp.com/contributor'}) |
||
289 | .setCreated(1111338494969) |
||
290 | .setCreator({ resource: 'https://myapp.com/creator'}) |
||
291 | .setModified(1111338494969)) |
||
292 | .addPerson( |
||
293 | GedcomX.Person() |
||
294 | .setId('testPerson') |
||
295 | .setPrivate(true) |
||
296 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
||
297 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
||
298 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) |
||
299 | ) |
||
300 | .addRelationship( |
||
301 | GedcomX.Relationship() |
||
302 | .setType('http://gedcomx.org/Couple') |
||
303 | .setPerson1(GedcomX.ResourceReference().setResource('http://identifier/for/person/1')) |
||
304 | .setPerson2(GedcomX.ResourceReference().setResource('http://identifier/for/person/2')) |
||
305 | .addFact(GedcomX.Fact().setType('http://gedcomx.org/Marriage')) |
||
306 | ) |
||
307 | .addSourceDescription( |
||
308 | GedcomX.SourceDescription() |
||
309 | .setId('sd1') |
||
310 | .setResourceType('http://some/type') |
||
311 | .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
||
312 | .setMediaType('book') |
||
313 | .setAbout('http://a/resource') |
||
314 | .setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
||
315 | .addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
||
316 | .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
||
317 | .setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
||
318 | .addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
||
319 | .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
||
320 | .addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
||
321 | .setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
||
322 | .addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
||
323 | .setCoverage( |
||
324 | GedcomX.Coverage() |
||
325 | .setTemporal(GedcomX.Date().setFormal('+2015')) |
||
326 | .setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
||
327 | ) |
||
328 | .addDescription(GedcomX.TextValue().setValue('A description')) |
||
329 | .setIdentifiers(GedcomX.Identifiers({ |
||
330 | $: 'identifier' |
||
331 | })) |
||
332 | .setCreated(1000000) |
||
333 | .setModified(11111111) |
||
334 | .setRepository(GedcomX.ResourceReference().setResource('http://repository')) |
||
335 | ) |
||
336 | .addAgent( |
||
337 | GedcomX.Agent() |
||
338 | .setId('agent') |
||
339 | .setIdentifiers(GedcomX.Identifiers({$:'ident'})) |
||
340 | .addName(GedcomX.TextValue().setLang('en').setValue('Name')) |
||
341 | .setHomepage(GedcomX.ResourceReference().setResource('http://homepage')) |
||
342 | .setOpenid(GedcomX.ResourceReference().setResource('http://openid')) |
||
343 | .addAccount(GedcomX.OnlineAccount().setAccountName('jimbo')) |
||
344 | .addEmail(GedcomX.ResourceReference().setResource('http://email')) |
||
345 | .addPhone(GedcomX.ResourceReference().setResource('http://phone')) |
||
346 | .addAddress(GedcomX.Address().setValue('big long address').setPostalCode('123456')) |
||
347 | .setPerson(GedcomX.ResourceReference().setResource('http://person')) |
||
348 | ) |
||
349 | .addEvent( |
||
350 | GedcomX.Event() |
||
351 | .setType('http://gedcomx.org/Marriage') |
||
352 | .setDate(GedcomX.Date().setFormal('+2002-06-06')) |
||
353 | .setPlace(GedcomX.PlaceReference().setOriginal('Her town, MN')) |
||
354 | .addRole(GedcomX.EventRole() |
||
355 | .setType('http://gedcomx.org/Participant') |
||
356 | .setPerson(GedcomX.ResourceReference().setResource('http://groom'))) |
||
357 | ) |
||
358 | .addDocument( |
||
359 | GedcomX.Document() |
||
360 | .setType('http://gedcomx.org/Abstract') |
||
361 | .setExtracted(false) |
||
362 | .setTextType('plain') |
||
363 | .setText('Lots of text') |
||
364 | .setAttribution(GedcomX.Attribution().setCreated(123456789)) |
||
365 | ) |
||
366 | .addPlace( |
||
367 | GedcomX.PlaceDescription() |
||
368 | .addName(GedcomX.TextValue().setLang('en').setValue('Pope\'s Creek, Westmoreland, Virginia, United States')) |
||
369 | .setType('http://identifier/for/the/place/type') |
||
370 | .setPlace(GedcomX.ResourceReference({ resource : 'http://place' })) |
||
371 | .setJurisdiction(GedcomX.ResourceReference({ resource : 'http://jurisdiction' })) |
||
372 | .setLatitude(27.9883575) |
||
373 | .setLongitude(86.9252014) |
||
374 | .setTemporalDescription(GedcomX.Date({ |
||
375 | formal: '+1899-01-04' |
||
376 | })) |
||
377 | .setSpatialDescription(GedcomX.ResourceReference({ |
||
378 | resource : 'http://uri/for/KML/document' |
||
379 | })) |
||
380 | ) |
||
381 | .addRecordDescriptor( |
||
382 | GedcomX.RecordDescriptor() |
||
383 | .setId('rd') |
||
384 | .setLang('en-US') |
||
385 | .addField( |
||
386 | GedcomX.FieldDescriptor() |
||
387 | .setOriginalLabel('Name') |
||
388 | .addDescription({ lang: 'en-US', value: 'Full Name' }) |
||
389 | .addValue( |
||
390 | GedcomX.FieldValueDescriptor() |
||
391 | .setOptional(true) |
||
392 | .setType('http://gedcomx.org/Original') |
||
393 | .setLabelId('name') |
||
394 | .addDisplayLabel({ lang: 'en-US', value: 'Name' }) |
||
395 | ) |
||
396 | ) |
||
397 | ) |
||
398 | .addCollection( |
||
399 | GedcomX.Collection() |
||
400 | .setId('collection') |
||
401 | .setLang('en-US') |
||
402 | .addContent( |
||
403 | GedcomX.CollectionContent() |
||
404 | .setResourceType('http://gedcomx.org/Record') |
||
405 | .setCount(183429102) |
||
406 | .setCompleteness(.8237) |
||
407 | ) |
||
408 | .setTitle('Collection Title') |
||
409 | .setSize(183429102) |
||
410 | .setAttribution( |
||
411 | GedcomX.Attribution() |
||
412 | .setContributor({ resource: 'https://myapp.com/contributor'}) |
||
413 | .setCreated(1111338494969) |
||
414 | .setCreator({ resource: 'https://myapp.com/creator'}) |
||
415 | .setModified(1111338494969) |
||
416 | ) |
||
417 | ); |
||
418 | |||
419 | tests(gedx); |
||
420 | }); |
||
421 | |||
422 | it('toJSON', function(){ |
||
423 | var gedx = GedcomX(fullJSON); |
||
424 | assert.deepEqual(gedx.toJSON(), fullJSON); |
||
425 | assert.jsonSchema(gedx.toJSON(), GedcomXSchema); |
||
426 | }); |
||
427 | |||
428 | }); |
||
429 | |||
558 | } |